//
//  UIButton+Addition.m
//  cleancar
//
//  Created by 郭平 on 14/10/27.
//  Copyright (c) 2014年 edaijia-inc. All rights reserved.
//

#import "UIButton+Addition.h"
#import "UIImage+Addition.h"

@implementation UIButton (Addition)

- (void) setBackgroundWithNormalImage:(NSString *)normalImg highlightedImage:(NSString *)highlightedImage
{
    UIImage *normal = [UIImage getStretchableImage:IMG(normalImg)];
    UIImage *highlighted = [UIImage getStretchableImage:IMG(highlightedImage)];
    [self setBackgroundImage:normal forState:UIControlStateNormal];
    [self setBackgroundImage:highlighted forState:UIControlStateHighlighted];
}

- (instancetype)initWithFrame:(CGRect)frame NormalTitile:(NSString *)titile Type:(ZYJButtonType)type
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitle:titile forState:UIControlStateNormal];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:15.f];
//        self.layer.cornerRadius = 15.f;
//        self.layer.masksToBounds = YES;
        UIImage *norImage = [UIImage imageWithColor:RGBCOLOR(0x38BE69)];
        UIImage *hightImage = [UIImage imageWithColor:RGBCOLOR(0x10A54F)];
        switch (type) {
            case ZYJGrayButtonType:{
                norImage = [UIImage imageWithColor:RGBCOLOR(0x262630)];
                hightImage = [UIImage imageWithColor:RGBCOLOR(0x262630)];
                [self setTitleColor:RGBCOLOR(0x48f6c2) forState:UIControlStateNormal];
            }
                break;
            case ZYJOrangeButtonType:{
                norImage = [UIImage imageWithColor:RGBCOLOR(0xFF9A00)];
                hightImage = [UIImage imageWithColor:RGBCOLOR(0xEF6A00)];
                break;
            }
            case ZYJDarkOrangeButtonType:{
                norImage = [UIImage imageWithColor:RGBCOLOR(0xEF6A00)];
                hightImage =  [UIImage imageWithColor:RGBCOLOR(0xE3591C)];
            }
            case ZYJGreenButtonType:{
                norImage = [UIImage imageWithColor:RGBCOLOR(0x69BA45)];
                hightImage =  [UIImage imageWithColor:RGBCOLOR(0x48f6c2)];
            }

                break;
            default:
                break;
        }
        [self setBackgroundImage:norImage forState:UIControlStateNormal];
        [self setBackgroundImage:hightImage forState:UIControlStateHighlighted];
        [self setBackgroundImage:[UIImage imageWithColor:RGBCOLOR(0x6c6c7d)] forState:UIControlStateDisabled];
    }
    return self;
}

- (instancetype)initWithTipsFrame:(CGRect)frame NormalTitile:(NSString *)titile {
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitle:titile forState:UIControlStateNormal];
        [self setTitleColor:kBlack6C6C7D forState:UIControlStateNormal];
        [self setTitleColor:RGBCOLOR(0x48f6c2) forState:UIControlStateSelected];
        self.titleLabel.font = [UIFont systemFontOfSize:13.f];
        self.layer.cornerRadius = frame.size.height/2.f;
        self.layer.masksToBounds = YES;
        UIImage *norImage = [UIImage imageWithColor:RGBCOLOR(0x2e2e3a)];
        UIImage *hightImage = [UIImage imageWithColor:RGBCOLOR(0x1c1c23)];
        [self setBackgroundImage:norImage forState:UIControlStateNormal];
        [self setBackgroundImage:hightImage forState:UIControlStateSelected];
        [self setBackgroundImage:[UIImage imageWithColor:RGBCOLOR(0x6c6c7d)] forState:UIControlStateDisabled];
    }
    return self;
}

- (instancetype)initWithSelectTipsFrame:(CGRect)frame NormalTitile:(NSString *)titile{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitle:titile forState:UIControlStateNormal];
        [self setTitleColor:kBlack666 forState:UIControlStateNormal];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        self.titleLabel.font = [UIFont systemFontOfSize:14.f];
        self.layer.cornerRadius = frame.size.height/2.f;
        self.layer.masksToBounds = YES;
        self.layer.borderColor = kBlack999.CGColor;
        self.layer.borderWidth = 0.5f;
        UIImage *norImage = [UIImage imageWithColor:[UIColor whiteColor]];
        UIImage *hightImage = [UIImage imageWithColor:RGBCOLOR(0x06d1b0)];
        [self setBackgroundImage:norImage forState:UIControlStateNormal];
        [self setBackgroundImage:hightImage forState:UIControlStateSelected];
        [self setBackgroundImage:[UIImage imageWithColor:RGBCOLOR(0x6c6c7d)] forState:UIControlStateDisabled];
    }
    return self;
}

- (instancetype)initWithHeroInstitutionFrame:(CGRect)frame title:(NSString *)title{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setTitleColor:kBlack999 forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:12.f];
        [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        self.layer.cornerRadius = frame.size.height/2.f;
        self.layer.masksToBounds = YES;
        self.layer.borderColor = kBlack999.CGColor;
        self.layer.borderWidth = 0.5f;
        UIImage *norImage = [UIImage imageWithColor:[UIColor whiteColor]];
        [self setBackgroundImage:norImage forState:UIControlStateNormal];
        self.contentEdgeInsets = UIEdgeInsetsMake(-1, 0, 0, 0);
    }
    return self;

}

- (instancetype)initWithConfirmFrame:(CGRect)frame NormalTitile:(NSString *)titile{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitle:titile forState:UIControlStateNormal];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:16.f];
        self.layer.cornerRadius = frame.size.height/2.f;
        self.layer.masksToBounds = YES;
        UIImage *norImage = [UIImage imageWithColor:RGBCOLOR(0X06D1B0)];
        [self setBackgroundImage:norImage forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageWithColor:RGBCOLOR(0x6c6c7d)] forState:UIControlStateDisabled];
    }
    return self;
}

- (instancetype)initWithCancleFrame:(CGRect)frame NormalTitile:(NSString *)titile{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitle:titile forState:UIControlStateNormal];
        [self setTitleColor:RGBCOLOR(0X06D1B0) forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:16.f];
        self.layer.cornerRadius = frame.size.height/2.f;
        self.layer.masksToBounds = YES;
        self.layer.borderColor = RGBCOLOR(0X06D1B0).CGColor;
        self.layer.borderWidth = 0.5f;
        UIImage *norImage = [UIImage imageWithColor:[UIColor whiteColor]];
        [self setBackgroundImage:norImage forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageWithColor:RGBCOLOR(0x6c6c7d)] forState:UIControlStateDisabled];
    }
    return self;
}
@end
